# -*- coding: utf-8 -*-


from HuobiDMService import HuobiDM
# import datetime
import time
import threading

URL = 'https://api.btcgateway.pro'
ACCESS_KEY = ''
SECRET_KEY = ''

dm = HuobiDM(URL, ACCESS_KEY, SECRET_KEY)

def xx(p1,p2):
    while True:
        # p1='BTC_CQ'
        # p2='BTC_NQ'
#        symbol = p1[:3]
#        dit ={'CW':'this_week','NW':'next_week','CQ':'quarter','NQ':'next_quarter'}
        try:
            a = dm.get_contract_depth(p1, 'step6')
            b = dm.get_contract_depth(p2, 'step6')
            a1 = b.get('tick').get('asks')[0][0]
            a2 = a.get('tick').get('bids')[0][0]
            a3 = b.get('tick').get('bids')[0][0]
            a4 = a.get('tick').get('asks')[0][0]
        except Exception as e:
            print(f'error is {e}')
            time.sleep(2)
#            continue
        diff = '%.4f'%((a1-a2)/a2)
        dif = '%.4f'%((a3-a4)/a4)
        
        print(f'{p1[:3]} 开仓价差，{dif}')
        print(f'{p1[:3]} 平仓--价差，{diff}')
    #    print(str(diff))
        time.sleep(30)

if __name__ == '__main__' :
#    threads=[]
    t1 = threading.Thread( target=xx,args= ('DOT_CQ','DOT_NQ'))
    t2 = threading.Thread( target=xx,args= ('ETH_CQ','ETH_NQ'))
    t3 = threading.Thread( target=xx,args= ('BTC_CQ','BTC_NQ'))
    # t4 = threading.Thread( target=xx,args= ('EOS_CQ','EOS_NQ'))
    t1.start()
    t2.start()
    t3.start()
    # t4.start()
    
 


